home *** CD-ROM | disk | FTP | other *** search
/ Pesquisa Dirigida / Pesquisa Dirigida.iso / JOGOS / parking.swf / scripts / countdownclock.as next >
Text File  |  2005-01-18  |  2KB  |  87 lines

  1. function CountdownClock()
  2. {
  3.    this.totaltime = new Number();
  4.    this.minutes = new Number();
  5.    this.seconds = new Number();
  6.    this.saveminutes = new Number();
  7.    this.saveseconds = new Number();
  8.    this.handlerObj = undefined;
  9.    this.changeHandler = new String();
  10. }
  11. CountdownClock.prototype = new MovieClip();
  12. CountdownClock.prototype.setData = function(minutes, seconds, startnow)
  13. {
  14.    this.saveminutes = minutes;
  15.    this.saveseconds = seconds;
  16.    this.minutes = minutes;
  17.    this.minutes_txt.text = "0" + this.minutes;
  18.    this.seconds = seconds;
  19.    if(this.seconds < 10)
  20.    {
  21.       this.seconds_txt.text = "0" + this.seconds;
  22.    }
  23.    else
  24.    {
  25.       this.seconds_txt.text = this.seconds;
  26.    }
  27.    this.totaltime = minutes * 60 + seconds;
  28.    if(startnow)
  29.    {
  30.       this.startCountdown();
  31.    }
  32. };
  33. CountdownClock.prototype.startCountdown = function()
  34. {
  35.    this.timerID = setInterval(this,"doCountdown",1000);
  36. };
  37. CountdownClock.prototype.stopCountdown = function()
  38. {
  39.    clearInterval(this.timerID);
  40. };
  41. CountdownClock.prototype.reset = function(startnow)
  42. {
  43.    this.setData(this.saveminutes,this.saveseconds,startnow);
  44. };
  45. CountdownClock.prototype.doCountdown = function()
  46. {
  47.    if(this.totaltime > 0)
  48.    {
  49.       this.totaltime--;
  50.       switch(true)
  51.       {
  52.          case this.seconds == 0:
  53.             this.seconds = 59;
  54.             this.seconds_txt.text = this.seconds;
  55.             this.minutes--;
  56.             this.minutes_txt.text = "0" + this.minutes;
  57.             break;
  58.          case this.seconds <= 10:
  59.             this.seconds--;
  60.             this.seconds_txt.text = "0" + this.seconds;
  61.             break;
  62.          default:
  63.             this.seconds--;
  64.             this.seconds_txt.text = this.seconds;
  65.       }
  66.    }
  67.    else
  68.    {
  69.       clearInterval(this.timerID);
  70.       this.executeCallback();
  71.    }
  72. };
  73. CountdownClock.prototype.setChangeHandler = function(funcname, obj)
  74. {
  75.    this.handlerObj = obj;
  76.    this.changeHandler = funcname;
  77. };
  78. CountdownClock.prototype.executeCallback = function()
  79. {
  80.    this.handlerObj[this.changeHandler](this);
  81. };
  82. CountdownClock.prototype.getTimeRemaining = function()
  83. {
  84.    return this.totaltime;
  85. };
  86. Object.registerClass("countdownclock",CountdownClock);
  87.